# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_pyname=scikit_image
_realname=scikit-image
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.25.2
pkgrel=1
pkgdesc='Image processing routines for SciPy (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://scikit-image.org/"
msys2_repository_url="https://github.com/scikit-image/scikit-image"
msys2_references=(
  'purl: pkg:pypi/scikit-image'
)
license=('spdx:BSD-3-Clause AND BSD-2-Clause AND MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-matplotlib>=3.5"
  "${MINGW_PACKAGE_PREFIX}-python-scipy>=1.8"
  "${MINGW_PACKAGE_PREFIX}-python-pywavelets>=1.1.1"
  "${MINGW_PACKAGE_PREFIX}-python-numpy>1.22"
  "${MINGW_PACKAGE_PREFIX}-python-networkx>=2.8"
  "${MINGW_PACKAGE_PREFIX}-python-imageio>=2.27"
  "${MINGW_PACKAGE_PREFIX}-python-tifffile>=2022.8.12"
  "${MINGW_PACKAGE_PREFIX}-python-pillow>=9.0.1"
  "${MINGW_PACKAGE_PREFIX}-python-lazy-loader>=0.3")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-pythran"
  "${MINGW_PACKAGE_PREFIX}-cython"
  "${MINGW_PACKAGE_PREFIX}-meson-python"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest>=7.0"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-cov>=2.11.0"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-localserver"
  "${MINGW_PACKAGE_PREFIX}-python-pooch")
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-pyamg: fast cg_mg mode of random walker segmentation")
options=('!strip' '!emptydirs')
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('e5a37e6cd4d0c018a7a55b9d601357e3382826d3888c10d0213fc63bff977dde')

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}"
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  msg "Python install for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  shopt -s globstar
  rm "${pkgdir}${MINGW_PREFIX}"/**/*.dll.a

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README.md"
}
